﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SanFranciscoModel.Alumno;

namespace SanFrancisco
{
    public partial class SearchAlumno : Form
    {
        private int _Tipo;
        private string _Texto;
        private SearchTipo _searchTipo;
        private int _Eliminar = 0;

        public SearchAlumno(int Tipo, string Texto, SearchTipo searchTipo)
        {
            _Tipo = Tipo;
            _Texto = Texto;
            _searchTipo = searchTipo;
            InitializeComponent();
        }


        public SearchAlumno(int Tipo, string Texto, SearchTipo searchTipo,int Eliminar)
        {
            _Tipo = Tipo;
            _Texto = Texto;
            _searchTipo = searchTipo;
            _Eliminar = Eliminar;
            InitializeComponent();
        }
        private void SearchAlumno_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'sanFranciscoDataSet.Alumno' table. You can move, or remove it, as needed.
          //  this.alumnoTableAdapter.Fill(this.sanFranciscoDataSet.Alumno);

            CargarGrilla();

        }


      

        //private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        //{
        //    if (e.ColumnIndex == 4)
        //    {
        //        MessageBox.Show((e.RowIndex + 1) + "  Row  " + (e.ColumnIndex + 1) + "  Column button clicked ");
        //    }
        //}

        private void btnBuscar2_Click(object sender, EventArgs e)
        {
            CargarGrilla();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void dataGridView1_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (((System.Windows.Forms.DataGridView)(sender)).CurrentCell.ColumnIndex == 3)
            {
                string DNI;
                object value = gridAlumno.Rows[e.RowIndex].Cells[0].Value;
                DNI = value.ToString();
                if (_Eliminar == 0)
                {
                    IngresoDNI ing = new IngresoDNI (_Tipo,  _Texto, _searchTipo,DNI);
                    this.Hide();
                    ing.StartPosition = FormStartPosition.CenterScreen;
                    ing.ShowDialog();
                    this.Close();
                }
                else
                {
                    BajaGeneral Baja = new BajaGeneral(_Tipo, _Texto, _searchTipo, DNI);
                    this.Hide();
                    Baja.StartPosition = FormStartPosition.CenterScreen;
                    Baja.ShowDialog();
                    this.Close();
                }
            }
            else if (((System.Windows.Forms.DataGridView)(sender)).CurrentCell.ColumnIndex == 4)
            {
                string DNI;
                object value = gridAlumno.Rows[e.RowIndex].Cells[0].Value;
                DNI = value.ToString();
                ListarAlumno a = new ListarAlumno(int.Parse(DNI));
                a.StartPosition = FormStartPosition.CenterScreen;
                this.Hide();
                a.ShowDialog();
                this.Close();
            }
            
        }

        private void txtNombre_KeyPress(object sender, KeyPressEventArgs e)
        {
          //  CargarGrilla();
        }

        private void CargarGrilla()
        {
            AlumnoDataContext Alumno = new AlumnoDataContext();
            gridAlumno.AutoGenerateColumns = false;
            gridAlumno.DataSource = Alumno.AlumnosBuscar(txtApellido.Text, txtNombre.Text, txtDNI.Text);
        }

        private void txtApellido_KeyPress(object sender, KeyPressEventArgs e)
        {
          //  CargarGrilla();
        }

        private void txtDNI_KeyPress(object sender, KeyPressEventArgs e)
        {
            Utils.SoloNumeros(sender, e);
           // CargarGrilla();
        }

        private void txtDNI_TextChanged(object sender, EventArgs e)
        {
            CargarGrilla();
        }

        private void txtNombre_TextChanged(object sender, EventArgs e)
        {
            CargarGrilla();
        }

        private void txtApellido_TextChanged(object sender, EventArgs e)
        {
            CargarGrilla();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        
    }
}
